﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace PushPinControl
{
    public partial class PushPinToggle : UserControl
    {
        
        public event EventHandler Pinned;
        public event EventHandler Unpinned;
        public bool IsPinned { get; set; }

        public PushPinToggle()
        {
            InitializeComponent();
            PushPinToggleButton.IsChecked = true;
        }

        private void ToggleButton_Checked(object sender, RoutedEventArgs e)
        {
            RotatePushPin(0);
            IsPinned = true;
            if (Pinned != null)
            {
                Pinned(this, EventArgs.Empty);
            }
        }

        private void ToggleButton_Unchecked(object sender, RoutedEventArgs e)
        {
            RotatePushPin(90);
            IsPinned = false;
            if (Unpinned != null)
            {
                Unpinned(this, EventArgs.Empty);
            }
        }

        private void RotatePushPin(int angle)
        {
            RotateTransform rotatePushPin = new RotateTransform();
            rotatePushPin.Angle = angle;
            rotatePushPin.CenterX = PushPinImage.Height / 2;
            rotatePushPin.CenterY = PushPinImage.Width / 2;
            PushPinImage.RenderTransform = rotatePushPin;
        }

    }
}
